<?php echo $this->Html->script('jquery.dataTables.js'); ?>
 

<script type="text/javascript">
    $(document).ready(function() {
        $('#browserList').dataTable({
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": "<?php echo $this->Html->Url(array('controller' => 'Items', 'action' => 'indexdata')); ?>"
        });
    });
</script>

    <div style="text-align:left;"class=" Category CategoriesLink">
        <h3 style="font-size:30px;">Categories</h3>
            <?php foreach ($categories as $category):?>
                <p><?php echo $this->Html->link($category['Category']['name'], array('controller'=>'categories','action'=>'view',$category['Category']['id']));?></p>
            <?php endforeach;?>
    </div>



<div id="pinkHeader" class="admin_right items index">
	<h2><?php echo __('Treasures'); ?></h2>
    <?php //if ($current_customer['group_id'] = 1): ?>

    <!-- Start merging -->
    <?php //echo $this->Paginator->sort('id', '<img src="/CakePHP/img/sortid.png" title="Sort by ID" alt= "Sort by ID" />', array('escape' => false)); ?> &nbsp;
    <?php //echo $this->Paginator->sort('itemname', '<img src="/CakePHP/img/sortname.png" title="Sort by name" alt= "Sort by name" />', array('escape' => false)); ?>
    <?php //endif; ?>


<?php if ($current_customer['group_id'] == 1): ?>
    <div class="actions ">
       <!-- <div id="search" style="text-align: left;">-->
                            <?php
                           /*     echo $this->Form->create('Item',array('action' => 'search'));
                                echo $this->Form->input('keywords', array('label' => 'Search for'));
                                echo $this->Form->end();*/
                            ?>
   <!--     </div>-->

    		<p style="list-style-type:none; margin-top:2%; margin-bottom:2%;"><?php echo $this->Html->link(__('Add New Item'), array('action' => 'add')); ?></p>

    </div>
	
	
	<table id="browserList" style="width:120%;" cellpadding="0" cellspacing="0" class="table table-bordered  table-hover">
    <thead>
        <tr>
            <th style="width:5%;">Id</th>
            <th style="width:25%;">Name</th>
            <th style="width:15%;">Brand</th>
            <!--<th style="width:10%;">Category</th>-->
            <th style="width:15%;">Location</th>
            <th style="width:10%;">Original Price</th>
            <th style="width:10%;">Is Consignment</th>
			<th style="width:40%;">Manage More</th>         
        </tr>
    </thead>
    <tbody>
        <tr>
            <td colspan="4" class="dataTables_empty">Loading data from server...</td>
        </tr>
    </tbody>
</table>



	<?php /*?><table cellpadding="5" cellspacing="0" class="table table-bordered table-hover">
        <tr>
                <th><?php echo $this->Paginator->sort('id'); ?></th>
                <th><?php echo $this->Paginator->sort('name'); ?></th>
                <th><?php echo $this->Paginator->sort('brand_id'); ?></th>

                <!--<th><?php echo $this->Paginator->sort('category_id'); ?></th>-->

                <th><?php echo $this->Paginator->sort('location'); ?></th>
                <th><?php echo $this->Paginator->sort('original_price'); ?></th>

                <th class="actions"><?php echo __('Manage more'); ?></th>
        </tr>
        <?php foreach ($items as $item): ?>
            <tr id = "item_<?php echo $item['Item']['id'];?>" class="item">
                <td><?php echo h($item['Item']['id']); ?>&nbsp</td>
                <td><?php echo $this->html->link($item['Item']['name'], array('controller' => 'items', 'action' => 'view', $item['Item']['id'])); ?></td>
                <td><?php echo h($item['Brand']['name']); ?>&nbsp</td>
                <!--<td><?php echo h($item['Category']['name']); ?>&nbsp</td>-->
                <td><?php echo h($item['Item']['location']); ?>&nbsp;</td>
                <td><?php echo h($item['Item']['original_price']); ?>&nbsp;</td>



                        <!--<td><?php echo $this->Html->image('item_images/'.$item['Item']['id'].'/'.$images['Image']['name'], array('width' => 175, 'height' => 175)); ?></td>-->


                <td style="width:25%;" class="actions">
                    <?php echo $this->Html->link(__('View'), array('action' => 'view', $item['Item']['id'])); ?>
                    <?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $item['Item']['id'])); ?>
                    
                </td>

            </tr>
        <?php endforeach; ?>
	</table>
<?php */?><?php endif;?>



	<p>
        <?php
       /* echo $this->Paginator->counter(array(
        'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
        ));*/
        ?>
    </p>

	<div class="paging">
	<?php
		/*echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
		echo $this->Paginator->numbers(array('separator' => ''));
		echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));*/
	?>
	</div>

</div>


<script type="text/javascript">
//<![CDATA[
     var items = <?php echo json_encode($items);?>;
     $('#ItemKeywords').keyup(function(e) {
         if (this.value != '') {
             for (k in items) {
                 if (items[k]['Item'].id == this.value||
                         items[k]['Item'].name.toLowerCase() == this.value.toLowerCase() ||
                         items[k]['Brand'].name.toLowerCase() == this.value.toLowerCase() ||
                         items[k]['Category'].name.toLowerCase() == this.value.toLowerCase() ||
                         items[k]['Item'].id.indexOf(this.value) >= 0 ||
                         items[k]['Item'].name.toLowerCase().indexOf(this.value.toLowerCase()) >= 0 ||
                         items[k]['Brand'].name.toLowerCase().indexOf(this.value.toLowerCase()) >= 0 ||
                         items[k]['Category'].name.toLowerCase().indexOf(this.value.toLowerCase()) >= 0
                          ) {
                     $('#item_'+items[k]['Item'].id).show();
                 }
                 else {
                     $('#item_'+items[k]['Item'].id).hide();
                 }
             }
         }
         else {
             $('.item').show();
         }
     });
//]]>
</script>